﻿using System;
using System.Data;

namespace Syno.Core.Output.DataDisplay
{
    public class HtmlTableDisplay : TextTableDisplay
    {
        public HtmlTableDisplay() : base()
        {
            _templateDisplay.Template = @"<h2>$heading</h2>
#foreach($row in $data.Rows)
#beforeall
<table >
<thead>
    <tr class='th'>
    #foreach($column in $data.Columns)
    #each
    <td><strong>$column</strong></td>
    #end

  </tr>
</thead>
<tbody>
#before

       <tr
#odd
       >
#even
       Class='alt'>
#each
    #foreach($column in $data.Columns)
    #each
    <td>${row.get_Item($column)}</td>
    #after
    #nodata
    Strange there are no columns
    #end
#after
    </tr>
#afterall
</tbody>
</table>
#nodata
<span>No data</span>
#end";
            HeadingBgColor = "#3399FF";
            RowBgColor = "#F0F3F0";
            RowBgColorAlt = "#F5F7F5";
            HeadingColor = "white";
            RowColor = "black";
        }

        public override string Display(DataTable data)
        {
            _templateDisplay.AddContext("headingBgColor", HeadingBgColor);
            _templateDisplay.AddContext("rowBgColor", RowBgColor);
            _templateDisplay.AddContext("rowBgColorAlt", RowBgColorAlt);
            _templateDisplay.AddContext("headingColor", HeadingColor);
            _templateDisplay.AddContext("rowColor", RowColor);
            _templateDisplay.AddContext("rowColorAlt", RowColor);
            return base.Display(data);
        }

        public string HeadingBgColor { get; set; }

        public string RowBgColor { get; set; }

        public string RowBgColorAlt { get; set; }

        public string HeadingColor { get; set; }

        public string RowColor { get; set; }
    }
}